﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using WPFExcelReport;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class TSTP
    {   public TSTP()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VABPOS();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
         
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
           
            if (dwMaster == null)
            {
              
                ABTP = "";
            }
            else
            {           
                if(dwMaster["ABPTP"].ToString().Trim()=="0")
                {
                    dwMaster["ABPTP"] =double.Parse(dwMaster["TPSTART"].ToString())+1;
                }
                ABTP = TMV.ABPAUFKRS + TMV.ABPAUFLFD + TMV.ABPBESCHICH+Helper.Left(dwMaster["TPSTART"].ToString()+"0000",4) + dwMaster["ABPTP"].ToString().PadRight(10);

            }
            //此时规则和AB52应当进行了装载
        }
        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (vlaue.Length < 11)
                return;
            dwData = TBMain.NewRow();
            dwData["ABPMANDANT"] = app.Mandant;
            dwData["ABPAUFKRS"] = vlaue.Substring(0, 2);
            dwData["ABPAUFLFD"] = vlaue.Substring(2, 6);
            SResult = TMV.QAB04FN(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(vlaue);
        } 
       
        public override void ComboBox_DropDownOpened(object sender, EventArgs e)
        {
            OnEXAUFChg(EXAUF);
            base.ComboBox_DropDownOpened(sender, e);
        }
    }
}